package com.example.fw;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.example.tests.ContactObject;

	public class Contacts {
       
		private Set<ContactObject> storedContacts = null;
       
		public Contacts(Collection<ContactObject> list) {
			storedContacts = new HashSet<ContactObject>(list);        
		}
       

		public Contacts withAdded(ContactObject contact) {              
			Contacts contacts2 = new Contacts(storedContacts);
			contact.setId("$$$");
			contacts2.storedContacts.add(contact);
			contact.setId(null);
			return contacts2;
		}
       
		public Contacts without(ContactObject contact) {                
			Contacts contacts2 = new Contacts(storedContacts);
			contacts2.storedContacts.remove(contact);
			return contacts2;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result
					+ ((storedContacts == null) ? 0 : storedContacts.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	Contacts other = (Contacts) obj;
	if (storedContacts == null) {
		if (other.storedContacts != null)
			return false;
	} else if (!storedContacts.equals(other.storedContacts))
		return false;
	return true;
		}

		public int size() {
			return storedContacts.size();
		}

		@Override
		public String toString() {
			return "Contacts [storedContacts=" + storedContacts + "]";
		}
		
		public ContactObject getSomeComtact() {
            return storedContacts.iterator().next();
     }

}